package com.bao.Servlet;

import com.alibaba.fastjson.JSON;
import com.bao.Emtity.region;
import com.bao.Service.RegionService;
import com.bao.ServiceImpl.RegionServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by TangBaoshan on 2018/8/7.
 */
@WebServlet(name = "FindRegionServlet")
public class FindRegionServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        request.setCharacterEncoding("utf-8");
        RegionService se = new RegionServiceImpl();
        region re = new region();
        if (request.getParameter("affiliating")!=null){
            int id = Integer.parseInt(request.getParameter("affiliating"));
            re = se.findregion(id);
        }
        if (request.getParameter("id")!=null){
            int id = Integer.parseInt(request.getParameter("id"));
            re = se.findparentIdregion(id);
        }
        String res = JSON.toJSONString(re);
        out.print(res);
        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
